package hivMultiCompartment;

import java.awt.BasicStroke;
import java.awt.Color;

import uchicago.src.sim.gui.Drawable;
import uchicago.src.sim.gui.SimGraphics;

/**
 * this class is the base class for all agents that moves on the discrete grid.
 * It include cells, which cannot overlap with each other and each takes one cell,
 * and also viral particles which can have multiple object in the same cell
 * @author Mithril
 *
 */

public class AgentOnGrid implements ObjectInGrid, Drawable {
	public int 			x, y;		// cache the ant's x,y location
	public Color		myColor;    // color of this agent
	public static BasicStroke      bugEdgeStroke = new BasicStroke( 2.0f );
	public static Model theModel;
	
	//this object could be in either kind of the following organs:
	public Organ2DSpace Organ2D;
	public OrganNonSpatial OrganNS;

	public AgentOnGrid () {
		x = 0;
		y = 0;
		myColor = Color.gray;
		Organ2D = null;
		OrganNS = null;
	}
	
	//overloading the constructor for different Organs
	public AgentOnGrid (Organ2DSpace organ) {
		this();
		Organ2D = organ;
	}
	
	public AgentOnGrid (OrganNonSpatial organ) {
		this();
		OrganNS = organ;
	}	
	
	public int getX() { return x; }
	public void setX( int i ) { x = i; }
	public int getY() { return y; }
	public void setY( int i ) { y = i; }
	public void setColor (Color c) {myColor = c;}
	
	public static void setModel (Model m) {
		theModel = m;
	}
	/**
	 * reset the organ which this agent is in.
	 * remove the previous organ
	 * @param organ
	 */
	public void resetOrgan (OrganGeneral organ) {
		//System.out.println("resetting organ!" + this.toString() +", to: "+ organ.toString());
		if (Organ2DSpace.class.isInstance(organ)) {
			Organ2D = (Organ2DSpace)organ;
			OrganNS = null;
		}
		else {
			Organ2D = null;
			OrganNS = (OrganNonSpatial)organ;
		}
	}
	
	/**
	 * return my organ, whichever is available
	 * @return
	 */
	public OrganGeneral getMyOrgan(){
		if (Organ2D != null) {
			return Organ2D;
		}else {
			return OrganNS;
		}
	}
	
	public void draw( SimGraphics g ) {
	   	g.drawFastRoundRect( myColor );
	    g.drawRectBorder( bugEdgeStroke, myColor );
    }
}
